﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBUnits
    {
        Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectUnitsAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectUnitsAll()
        {
            return db.GetDataset("sp_SelectUnitsAll");
        }

        /// <summary>
        /// SelectUnit
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectUnitsByAndUnitID(Units obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UnitID", obj.UnitID),
            };
            return db.GetDataSetWithParameter("sp_SelectUnitsByAndUnitID", listParameter);
        }

        /// <summary>
        /// DeleteUnit
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteUnit(Units obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UnitID", obj.UnitID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteUnit", listParameter);
        }

        /// <summary>
        /// InsertUnit
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertUnit(Units obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UnitID", obj.UnitID),
                new SqlParameter("@UnitName", obj.UnitName),
                new SqlParameter("@Description", obj.Description),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
            };
            return db.ExcuteQueryWithParamater("sp_InsertUnit", listParameter);
        }

        /// <summary>
        /// UpdateUnit
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateUnit(Units obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UnitID", obj.UnitID),
                new SqlParameter("@UnitName", obj.UnitName),
                new SqlParameter("@Description", obj.Description),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
            };
            return db.ExcuteQueryWithParamater("sp_UpdateUnit", listParameter);
        }
    }
}